#!/usr/bin/env escript
%% @author: Jean-Lou Dupont
%%
-mode(compile).
-export([main/1]).

%% defines... 
srcpath() ->
	"src".
	
docpath() ->
	"doc".

main([]) ->
	{ok, Files}=file:list_dir(srcpath()),
	%io:format("> Files [~p]~n", [Files]),
	Sources=sources(Files),
	io:format("> Sources [~p]~n", [Sources]),
	{ok, Cd}=file:get_cwd(),
	%io:format("> Current working dir [~p]~n", [Cd]),
	Path=Cd++"/"++srcpath(),
	AbsSources=make_abs(Path, Sources),
	%io:format(">Abs files [~p]~n", [AbsSources]),
	DocPath=Cd++"/"++docpath(),
	edoc:files(AbsSources, [{dir, DocPath}]).
	
	
	
sources(Liste) ->
	lists:filter(fun(Elem) -> is_source(Elem) and is_not_test(Elem) end,Liste). 

is_source(File) ->
	case string:str(File, ".erl") of
		0 -> false;
		_ -> true
	end.
	
is_not_test(File) ->
	case string:str(File, "test") of
		0 -> true;
		_ -> false
	end.
	
	
make_abs(Path, Liste) ->
	lists:flatmap(fun(Elem) -> [Path++"/"++Elem] end, Liste).
